package com.example.dmy.kafkastorm.job;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author: daimengying
 * @Date: 2019/1/3 14:31
 * @Description:定时发送Kafka消息,2秒执行一次
 */
@Slf4j
@Component
public class sendMessageJob {
    @Autowired
    private KafkaTemplate kafkaTemplate;

    @Scheduled(cron = "0/2 * * * * *")
    public void scheduled(){
        kafkaTemplate.send("test", new Date().toString());
    }
}
